package com.car.service;

import com.car.dao.PurchaseRecordDao;
import com.car.dao.impl.PurchaseRecordDaoImpl;
import com.car.domain.Car;
import com.car.domain.Employee;
import com.car.domain.PurchaseRecord;
import com.car.utils.NumberUtil;

import java.util.List;
import java.util.Scanner;

import static com.car.dao.impl.CarDaoImplTest.carDao;

public class PurchaseRecordService {
    private final static PurchaseRecordDao purchaseRecordDao = new PurchaseRecordDaoImpl();

    public List<PurchaseRecord> findByUserId(String userId) throws Exception{
        return purchaseRecordDao.findByUserId(userId);
    }
    public void addCar (Employee employee, Scanner scanner) throws Exception {
        System.out.println("汽车上架");
        Car car = new Car();
        System.out.println("请输入汽车名字: ");
        String name = scanner.next();
        car.setName(name);
        System.out.println("请输入汽车的品牌");
        String brank= scanner.next();
        car.setBrand(brank);
        System.out.println("请输入汽车的颜色: ");
        String color =scanner.next();
        car.setColor(color);
        System.out.println("请输入汽车是类型");
        String  type = scanner.next();
        car.setType(type);
        System.out.println("请输入汽车的价格: ");
        double price = scanner.nextDouble();
        car.setPrice(price);
        car.setCarNum(NumberUtil.generateCardNum());
        car.setEmployeeId((Integer) employee.getId());
        int i = carDao.add(car);
        if (i>0){
            System.out.println("上架成功");
        }else {
            System.out.println("操作失败");
        }
    }

    public List<PurchaseRecord> list() {
        return null;
    }
}
